<!DOCTYPE html>
<html class="Content">
<head>
    <title>xUnit.js: Data-Driven Tests</title>
    <link type="text/css" rel="Stylesheet" href="../../Style/documentation.css" />
</head>
<body>
    <h1>Data-Driven Tests</h1>
    <p>
        This example is based on <em>Examples/Source/Data-Driven Tests/DataTests.js</em> from <a href="examples.zip">examples.zip</a>.
    </p>
    <p>
        Often, it can be useful to run a single test with different sets of expectations. To accomplish this, xUnit.js provides the concept of <em>Fact</em><strong>.Data</strong>. 
        In the console runner, this is exposed through the <strong>Data(</strong><em>values</em><strong>)</strong> attribute.
    </p>
    <h3>Test:</h3>
    <p>
        <span class="Code">
Function.RegisterNamespace("Test");

[Fixture]
Test.DataTests=function(){
	[Fact, Data(1,2,3,4)]
	function VerifiesDataIsInRange(data){
		var expectedLow = 1;
		var expectedHigh = 3;

		var actual=data;

		Assert.InRange(actual,expectedLow,expectedHigh);
	}
}
        </span>
    </p>
    <p>
        In the test above, we are supplying four separate values, the numbers 1 to 4, as the data we are expecting in our test. This will cause the fact to be run four times, once for each value.
        This value is supplied as an argument for the parameter "data", which is then collected as our actual, for the purpose of comparing to our low and high expectations. 
    </p>
    <p>
        Looking at the expectations, then, we can tell that this test will pass three times, for the values 1 to 3, and fail once, for the value 4, which falls outside of our intended range of values.
    </p>
    <p>
        Any javascript value can be supplied as a piece of data, from primitives such as Booleans, Numbers and Strings, to complex Objects, Arrays, and even Functions.
    </p>
</body>
</html>